﻿// Author: AustralTek 
// Create date: 2010/05/04
// http://www.australtek.com
// Copyright: 2009 - 2010

(function () {
    function _AsyncParameters(options) {
        try {
            var privateParameters;
            var form;
            function _initialize(options) {
                try {
                    privateParameters = new PrivateParameters(options);

                } catch (Error) { privateParameters.Events.onError(Error); }
            };

            function _setParameter(key, value) {
                try {
                    if (form) {
                        for (i = 0; i < form.length; i++) {
                            if (form[i].name == key) {
                                form[i].value = value;
                                break;
                            }
                        }
                    }
                } catch (Error) { privateParameters.Events.onError(Error); }
            };
            function _removeParameter(key) {
                try {
                    if (form) {
                        for (i = 0; i < form.length; i++) {
                            if (form[i].name == key) {
                                form[i].value = '';
                                break;
                            }
                        }
                    }
                } catch (Error) { privateParameters.Events.onError(Error); }
            };
            function _sendAsyncParameters() {
                try {
                    if (form != undefined) form.submit();
                } catch (Error) { privateParameters.Events.onError(Error); }
            }
            function _setForm(tempForm) {
                try {
                    form = tempForm;                  
                } catch (Error) { privateParameters.Events.onError(Error); }
            };

            _initialize(options);

            this.SetParameter = function (key, value) {
                _setParameter(key, value);
            };
            this.RemoveParameter = function (key) {
                _removeParameter(key);
            };
            this.sendAsyncParameters = function () {
                _sendAsyncParameters();
            };
            this.SetForm = function (form) {
                _setForm(form);
            };

        } catch (Error) { };
    };

    window.AsyncParameters = function (options) { return new _AsyncParameters(options) };
})();